<?php
/**
 * 活动管理
 * @author ***
 *
 */
class SpecialAction extends HomeAction {
    public function _initialize() {
        parent::_initialize();
    }
    public function special() {
        global $user, $language_id;
        $data = array(
            'docTitle' => L('meta_title_special') ,
            'docKeywords' => L('meta_keywords') ,
            //'docDescription' => L('meta_description'),
            
        );
        $this->assign($data);
        $this->assign('robots', 'noindex');
        $this->display('special/fifty-percent-off/index');
    }
    //世界杯页面
    public function worldcup() {
        global $user;
        //url 301重定向
        send_http_status(301);
        redirect(url('/'));
        exit;
        $data = array(
            'docTitle' => L('meta_title_worldcup') ,
            'docKeywords' => L('meta_keywords') ,
            'docDescription' => L('meta_description') ,
        );
        $this->assign($data);
        //注册人数
        $user_db = D('users');
        $userCount = $user_db->count();
        $this->assign('userCount', $userCount);
        //最新参加世界杯活动一条数据
        $worldup_db = D('worldup');
        $worldup = $worldup_db->table('worldup world,users users')->order('time DESC')->where(array(
            'world.user_id=users.id'
        ))->limit(1)->select();
        $this->assign('worldup', $worldup);
        $worldup_db = D('worldup');
        $worldupCount = $worldup_db->table('worldup world,users users')->order('time DESC')->where(array(
            'world.user_id=users.id'
        ))->limit(10)->select();
        $this->assign('worldupCount', $worldupCount);
        //世界杯活动显示为各语言
        $worldcup_array = array(
            'brazil' => 'worldup_3',
            'croatia' => 'worldup_4',
            'mexico' => 'worldup_5',
            'cameroon' => 'worldup_6',
            'spain' => 'worldup_7',
            'netherlands' => 'worldup_8',
            'chile' => 'worldup_9',
            'australia' => 'worldup_10',
            'colombia' => 'worldup_11',
            'greece' => 'worldup_12',
            'cote-divoire' => 'worldup_13',
            'japan' => 'worldup_14',
            'uruguay' => 'worldup_15',
            'costa-rica' => 'worldup_16',
            'england' => 'worldup_17',
            'italy' => 'worldup_18',
            'switzerland' => 'worldup_19',
            'ecuador' => 'worldup_20',
            'france' => 'worldup_21',
            'honduras' => 'worldup_22',
            'argentina' => 'worldup_23',
            'bosnia-herzegovina' => 'worldup_24',
            'iran' => 'worldup_25',
            'nigeria' => 'worldup_26',
            'germany' => 'worldup_27',
            'portugal' => 'worldup_28',
            'ghana' => 'worldup_29',
            'usa' => 'worldup_30',
            'belgium' => 'worldup_31',
            'algeria' => 'worldup_32',
            'russia' => 'worldup_33',
            'korea' => 'worldup_34',
        );
        $this->assign('worldcup_array', $worldcup_array);
        $this->display('special/world-cup/index');
    }
    //用户是否登录
    public function worldCup_ajax() {
        send_http_status(404);
        $this->display(C('ERROR_PAGE'));
        exit;
        global $user, $language_id;
        $post = $_POST;
        $result = array(
            'status' => 'failure',
            'message' => '',
        );
        if (isset($user['id']) && $user['id']) {
            //检查用户是否已参与过活动
            $worldup_db = D('worldup');
            $worldup_info = $worldup_db->where(array(
                'user_id' => $user['id']
            ))->find();
            if ($worldup_info) {
                $result['status'] = 'failure';
                $result['message'] = L('_participate_');
                echo json_encode($result);
                exit;
            }
            $worldup_db = D('worldup');
            $data['country'] = $post['country'];
            $data['user_id'] = $user['id'];
            $data['time'] = time();
            $last_id = $worldup_db->add($data);
            if ($last_id) {
                $result['status'] = 'success';
                $result['message'] = L('_succeed_');
                echo json_encode($result);
                exit;
            } else {
                $result['status'] = 'failure';
                $result['message'] = L('_fail_');
                echo json_encode($result);
                exit;
            }
        } else {
            $result['status'] = 'unlogin';
            $result['message'] = L('_nologin_');
            echo json_encode($result);
            exit;
        }
    }
    //用户登录
    public function worldcuplogin_ajax() {
        global $user;
        $post = $_POST;
        $result = array(
            'status' => 'failure',
            'message' => '',
        );
        if (UserModel::logged()) {
            $user_info = UserModel::get_user_info($user_id);
            if (!$user_info['disabled']) {
                $this->error(L('_MEMBER_ACCOUNT_HAS_BEEN_DISABLED_PLEASE_CONTACT_YOUR_ADMINISTRATOR_'));
            }
            session('user_id', $user_id);
        } else {
            $username = trim($post['username']);
            $password = trim($post['password']);
            $login_vcode = strtolower($post['login_vcode']);
            if (C('vcode_login') == 1) {
                if ($_SESSION['login_vcode'] != $login_vcode) {
                    $result = array(
                        'status' => 'failure',
                        'message' => L('_VERIFICATION_ERROR_') ,
                    );
                    echo json_encode($result);
                    exit;
                }
            }
            $username = trim($post['username']);
            $password = trim($post['password']);
            //登录验证
            if (!$user_id = UserModel::validate_user($username, $password)) {
                $result = array(
                    'status' => 'failure',
                    'message' => L('_LOGIN_FAILED_THE_USER_NAME_OR_PASSWORD_ERROR_') ,
                );
                echo json_encode($result);
                exit;
            }
            $result['status'] = 'success';
            $result['message'] = L('_yeslogin_');
            session('user_id', $user_id);
            //更新用户数据
            UserModel::setLogin($user_id);
            //合并购物车
            CartModel::mergeCart($user['sid']);
            echo json_encode($result);
            exit;
        }
    }
    //用户注册
    public function worldcupReg_ajax() {
        global $user, $language_id;
        $post = $_POST;
        $result = array(
            'status' => 'failure',
            'message' => '',
        );
        if (UserModel::logged()) {
            $result['status'] = 'success';
            $result['message'] = L('_LOGINED_SUCCESS_');
            echo json_encode($result);
            exit;
        } else {
            //两次输入密码是否一致
            $email = trim($post['email']);
            $password = trim($post['regpassword']);
            $confirm_password = trim($post['confirm_password']);
            if (empty($email) || $password != $confirm_password) {
                $result = array(
                    'status' => 'failure',
                    'message' => '',
                );
                echo json_encode($result);
                exit;
            }
            //检查用户是否存在
            $user = D('users');
            $loginexit = $user->where(array(
                'email' => $post['email']
            ))->find();
            if ($loginexit) {
                $result = array(
                    'status' => 'email_exist',
                    'message' => L('_USER_NAME_ALREADY_EXISTS_') ,
                );
                echo json_encode($result);
                exit;
            }
            //查看POST值是否存在
            $post['password'] = $password;
            if (!$user_id = UserModel::insert_user($post)) {
                $result = array(
                    'status' => 'failure',
                    'message' => '',
                );
                echo json_encode($result);
                exit;
            } else {
                //用户注册送红包
                session('user_id', $user_id);
                UserModel::user_bonus('register', $user_id);
            }
            $result['status'] = 'success';
            $result['message'] = L('registory_success');
            echo json_encode($result);
            exit;
        }
    }
    /*
     * 好友邀请活动
    */
    public function referfriend() {
        $tel = $_GET['tel'] ? base64_decode($_GET['tel']) : ""; //邀请人手机号
        if ($_POST['dosubmit'] == 1) {
            //判断手机号是否领过优惠码
            $user_mobile = $_POST['cellphone'];
            if (S('referfriend_mobile' . $user_mobile)) { //先查缓存
                //获取此手机号领取的相关信息
                $info_coupon = S('referfriend_mobile' . $user_mobile);
                cookie('is_coupon_info', 1);
                redirect(url('special/referfriend_result', array(
                    'tel' => base64_encode($user_mobile) ,
                    'info_coupon' => base64_encode($info_coupon)
                )));
                exit;
            } else {
                //领取的信息
                $info_coupon = D("refe_invite_items")->where(array(
                    'invited_mobile' => $user_mobile
                ))->getField('invite_coupon_code');
                if ($info_coupon) {
                    S('referfriend_mobile' . $user_mobile, $info_coupon, 2 * 60 * 60);
                    cookie('is_coupon_info', 1);
                    redirect(url('special/referfriend_result', array(
                        'tel' => base64_encode($user_mobile) ,
                        'info_coupon' => base64_encode($info_coupon)
                    )));
                    exit;
                } else {
                    //生成受邀请人的优惠码
                    $invited['coupon_code'] = get_str_coupon(7) . date("d", time());
                    $invited['coupon_money'] = 200;
                    $invited['max_amount'] = 1000000;
                    $invited['min_amount'] = 300;
                    $invited['expiration_time'] = time() + 180 * 24 * 60 * 60;
                    $invited['status'] = 2;
                    $favorable_db = M('favorable');
                    $invited_coupon_id = $favorable_db->add($invited);
                    if ($invited_coupon_id) {
                        if ($tel) {
                            $setsql['user_mobile'] = $tel;
                        }
                        $setsql['invited_mobile'] = $user_mobile;
                        $setsql['invited_coupon_id'] = $invited_coupon_id;
                        $info_coupon = $setsql['invite_coupon_code'] = $invited['coupon_code'];
                        $setsql['use_status'] = 0;
                        $setsql['dt_add'] = time();
                        $last_id = D("refe_invite_items")->add($setsql);
                        if ($last_id) {
                            S('referfriend_mobile' . $user_mobile, $info_coupon, 2 * 60 * 60);
                            cookie('self_coupon', $info_coupon); //把优惠码存入cookie
                            cookie('is_coupon_info', 1);
                            redirect(url('special/referfriend_result', array(
                                'tel' => base64_encode($user_mobile) ,
                                'info_coupon' => base64_encode($info_coupon)
                            )));
                        }
                    } else { //领取失败 返回领取页面重新领取
                        redirect(url('special/referfriend', array(
                            'tel' => base64_encode($tel)
                        )));
                    }
                }
            }
        } else {
            $this->display('/special/refer-friend/index');
        }
    }
    //领取结果页面
    public function referfriend_result() {
        $data = array(
            'docTitle' => "ownonly送您200元红包，邀请你体验ownonly男装定制",
        );
        $user_mobile = $_GET['tel'] ? base64_decode($_GET['tel']) : ""; //受邀人手机号->邀请人手机号
        $is_coupon_info = cookie('is_coupon_info') ? cookie('is_coupon_info') : "";
        if (!$is_coupon_info) {
            redirect(url('special/referfriend', array(
                'tel' => base64_encode($user_mobile)
            )));
        }
        $data['coupon'] = $info_coupon = base64_decode($_GET['info_coupon']);
        //返现信息
        if (S('referfriend_coupon_' . $user_mobile)) {
            $data['info_use'] = S('referfriend_coupon_' . $user_mobile);
        } else {
            $data['info_use'] = D("refe_invite_items")->where(array(
                'user_mobile' => $user_mobile,
                "use_status" => 1
            ))->order('id desc')->limit(0, 10)->select();
            S('referfriend_coupon_' . $user_mobile, $data['info_use'], 2 * 60 * 60);
        }
        $data['qrcode'] = url('phpqrcode/index', array(
            'url' => base64_encode("http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'])
        ));
        $this->assign($data);
        $this->display('/special/refer-friend/got-coupon');
    }
    //好友邀请活动中，发送邮件中的get it now跳转页面
    public function coupon($code) {
        if (!C('invite_switch')) { //邀请好友活动开关
            redirect('/');
            exit;
        }
        $coupon_info = M('favorable')->where("coupon_code='" . $code . "'")->find();
        if (!$coupon_info && $coupon_info['status'] != 2) {
            redirect('/');
            exit;
        }
        global $language_id;
        $language = SiteModel::get_language_list();
        $lang = $language[$language_id];
        $EUR_list = array(
            'fr',
            'it',
            'de'
        ); //欧元国家计算汇率
        // $USD_list = array('en-us','es','ru');//美元区国家
        $currencies = SiteModel::currency_list();
        $currency = $currencies['EUR']; //欧元汇率信息
        if (in_array($lang['directory'], $EUR_list)) { //计算欧元优惠金额
            $coupon_money = number_format($currency['exchange'] * 50, 1);
            if ($lang['directory'] == 'it') {
                $coupon_money = str_replace('.', ',', (string)$coupon_money); //意大利语 货币转换成 (38,2)格式 普通为38.2
                
            }
        } else { //美元区处理
            $coupon_money = 50;
        }
        $refer_getitnow_title = str_replace('|_coupon_money_|', $coupon_money, L('refer_getitnow_title'));
        cookie('self_coupon', $code, 'expire=604800&path=/&domain=' . APP_DOMAIN); //把优惠码存入cookie
        $this->assign('refer_getitnow_title', $refer_getitnow_title);
        $this->assign('coupon_code', $code);
        $this->display('/index/index_real');
    }
    //移动端推荐朋友首页
    public function promotion() {
        $this->display('special/promotion/index');
    }
    /*
     *  9月营销活动 搭配套餐优惠
    */
    public function package() {
        send_http_status(301);
        redirect(url('/'));
        exit;
        global $language_id;
        $data = array(
            'docTitle' => L('meta_title_package') ,
            'docKeywords' => L('meta_keywords') ,
            'docDescription' => L('meta_description') ,
        );
        $this->assign($data);
        $package = array(
            //套餐列表array('西装id'-suit_id,'衬衫id'-shirt_id,'配饰id'-accessories_id)
            '1' => array(
                'suit_id' => 374,
                'shirt_id' => 376,
                'accessories_id' => 250
            ) ,
            '2' => array(
                'suit_id' => 198,
                'shirt_id' => 312,
                'accessories_id' => 366
            ) ,
            '3' => array(
                'suit_id' => 180,
                'shirt_id' => 314,
                'accessories_id' => 367
            ) ,
            '4' => array(
                'suit_id' => 387,
                'shirt_id' => 131,
                'accessories_id' => 549
            ) ,
            '5' => array(
                'suit_id' => 445,
                'shirt_id' => 471,
                'accessories_id' => 210
            ) ,
        );
        $productList = ProductModel::get_product_package_list($package, $language_id);
        $this->assign('productList', $productList);
        $this->display('/special/package/index');
    }
    /*
     * 黑色星期五广告页面
    */
    public function activitySummary() {
        send_http_status(301);
        redirect(url('/'));
        exit;
        $data = array(
            'docTitle' => L('meta_title_activitySummary') ,
            'docKeywords' => L('meta_keywords') ,
            'docDescription' => L('meta_description') ,
        );
        $this->assign($data);
        $this->display('/special/activity-summary/index');
    }
    /*
     * 圣诞节抽奖页面
    */
    public function christmas() {
        //url 301重定向
        send_http_status(301);
        redirect(url('/'));
        exit;
        header("Pragma: no-cache");
        header("Cache-Control: no-cache");
        header("Expires: 0");
        global $user, $language_id;
        //print_r(ActivityModel::christmasLotteryCount());exit;
        $docTitle = L('christmas_share_1');
        $this->assign('docTitle', $docTitle);
        //$docKeywords =
        $docDescription = L('christmas_share_2');
        $this->assign('docDescription', $docDescription);
        $ShareName = array();
        $LotteryNumber = 0;
        if (UserModel::logged()) {
            ActivityModel::christmasAddShare('default');
            $ShareName = ActivityModel::christmasShareName($user['id']);
            $LotteryNumber = ActivityModel::christmasShareCount($user['id']);
        }
        $this->assign('ShareName', $ShareName);
        $this->assign('LotteryNumber', $LotteryNumber);
        $productArr = array(
            173,
            177,
            497,
            650,
            649
        );
        $productList = ProductModel::get_product_collection_list($productArr); //推荐产品
        $this->assign('productList', $productList);
        $this->assign('islogin', UserModel::logged());
        $this->assign('loginSrc', 'src=' . base64_encode(url('special/christmas')));
        $this->assign('logoutSrc', 'src=' . base64_encode(url('special/christmas')));
        $this->display('special/christmas/index');
    }
    /*
     * 圣诞节抽奖页面 分享处理
    */
    public function christmasShare() {
        global $user, $language_id;
        if (!UserModel::logged()) {
            $info = array(
                'error' => 1,
                'errStr' => L('_USER_NO_LOGINED_') ,
            );
            echo json_encode($info);
            exit;
        }
        //分享的类型
        $sharetype = array(
            'facebook',
            'twitter',
            'google',
            'pinterest',
            'email',
            'vk',
            'linkedin'
        );
        //分享类型的判断
        $shareName = $_REQUEST['shareName'];
        if (!in_array($shareName, $sharetype)) {
            $info = array(
                'error' => 2,
                'errStr' => 'Share the way errors',
            );
            echo json_encode($info);
            exit;
        }
        ActivityModel::christmasAddShare($shareName);
        $info = array(
            'error' => 0,
            'errStr' => '',
            'LotteryNumber' => ActivityModel::christmasShareCount($user['id']) ,
        );
        echo json_encode($info);
        exit;
    }
    /*
     * 圣诞节抽奖页面 分享处理
    */
    public function christmasLottery() {
        global $user, $language_id;
        if (!UserModel::logged()) {
            $info = array(
                'error' => 1,
                'errStr' => L('_USER_NO_LOGINED_') ,
            );
            echo json_encode($info);
            exit;
        }
        $starttime = strtotime(C('christmas_cart_startdata'));
        $endtime = strtotime(C('christmas_cart_enddata'));
        $nowtime = time();
        if ($nowtime < $starttime) {
            $info = array(
                'error' => 3,
                'errStr' => '',
            );
            echo json_encode($info);
            exit;
        } else if ($nowtime > $endtime) {
            $info = array(
                'error' => 4,
                'errStr' => '',
            );
            echo json_encode($info);
            exit;
        }
        $LotteryNumber = ActivityModel::christmasShareCount($user['id']);
        if ($LotteryNumber < 1 || !$getLotteryRes = ActivityModel::christmasLottery($user['id'])) {
            $info = array(
                'error' => 2,
                'errStr' => '',
            );
            echo json_encode($info);
            exit;
        }
        $info = array(
            'error' => 0,
            'errStr' => '',
            'returnId' => $getLotteryRes['getId'],
            'returnType' => $getLotteryRes['getRes'],
            'returnMsg' => $getLotteryRes['returnMsg'],
            'LotteryNumber' => ActivityModel::christmasShareCount($user['id']) ,
        );
        echo json_encode($info);
        exit;
    }
    /*
     * 圣诞节抽奖页邮件分享处理
    */
    public function christmasShareEmail() {
        global $language_id;
        $friendName = $_REQUEST['friendName'];
        $friendEmail = $_REQUEST['friendEmail'];
        $language = SiteModel::get_language_list();
        $lang = $language[$language_id];
        if ($lang['directory'] == 'en-us') {
            $url = 'http://www.' . APP_DOMAIN; //获得当前发送邮件中用户需要跳转域名地址
            
        } else {
            $url = 'http://' . $lang['directory'] . '.' . APP_DOMAIN;
        }
        $togoUrl = '<a href="' . $url . '/special/christmas">' . $url . '/special/christmas</a>';
        $contentOr = array(
            '{$url}',
            '{$date}'
        );
        $contentRe = array(
            $togoUrl,
            date('Y-m-d', time())
        );
        ActivityModel::sendXmasEmail($friendEmail, 'ChristmasShare', false, false, $contentOr, $contentRe);
    }
    /*
     * 圣诞节得奖邮件处理
    */
    public function christmasPrizeEmail() {
        global $user, $language_id;
        if (!UserModel::logged()) {
            exit;
        }
        $id = $_REQUEST['id'];
        $christmas_result_db = D('christmas_result');
        $where = array(
            'id' => $id,
            'is_used' => 1,
            'coupon_used' => 0,
        );
        $result = $christmas_result_db->field('user_id,prize_type,prize_content')->where($where)->find();
        if ($result) {
            $prize_content = $result['prize_content'];
            if ($result['prize_type'] == 5) {
                $template = "ChristmasCouponshirt";
            } else if ($result['prize_type'] == 6) {
                $template = "ChristmasCouponsuit";
            } else {
                exit;
            }
            $userInfo = UserModel::get_user_info($result['user_id']);
            $contentOr = array(
                '{$coupon_code}',
                '{$date}'
            );
            $contentRe = array(
                $prize_content,
                date('Y-m-d', time())
            );
            ActivityModel::sendXmasEmail($userInfo['email'], $template, false, false, $contentOr, $contentRe);
        }
    }
    //转盘
    public function fortunewheel() {
        global $user, $language_id;
        //url 301重定向
        send_http_status(301);
        redirect(url('/'));
        exit;
        $docTitle = L('fortunewheel_share_Title');
        $this->assign('docTitle', $docTitle);
        //$docKeywords =
        $docDescription = L('fortunewheel_share_Description');
        $this->assign('docDescription', $docDescription);
        $fortunewheelLottery = array();
        $isLottery = 0;
        if (UserModel::logged()) {
            ActivityModel::christmasAddShare('default');
            $fortunewheelLottery = ActivityModel::fortunewheelLotteryCount($user['id']);
            if ($fortunewheelLottery) $isLottery = 1;
        }
        $this->assign('fortunewheelLottery', $fortunewheelLottery);
        $this->assign('isLottery', $isLottery);
        //推荐产品
        $productArr = array(
            650,
            654,
            173,
            474,
            307
        );
        $productList = ProductModel::get_product_collection_list($productArr);
        $this->assign('productList', $productList);
        //查最近中奖的用户
        $this->assign('fortunewheelList', ActivityModel::fortunewheelList());
        $this->assign('islogin', UserModel::logged());
        $this->assign('loginSrc', 'src=' . base64_encode(url('special/fortunewheel')));
        $this->assign('logoutSrc', 'src=' . base64_encode(url('special/fortunewheel')));
        $this->display('special/fortune-wheel/index');
    }
    /*
     * 转盘页面 处理
    */
    public function fortunewheelLottery() {
        global $user, $language_id;
        if (!UserModel::logged()) {
            $info = array(
                'error' => 1,
                'errStr' => L('_USER_NO_LOGINED_') ,
            );
            echo json_encode($info);
            exit;
        }
        $starttime = strtotime(C('fortunewheel_starttime'));
        $endtime = strtotime(C('fortunewheel_endtime'));
        $nowtime = time();
        if ($nowtime < $starttime) {
            $info = array(
                'error' => 3,
                'errStr' => '',
            );
            echo json_encode($info);
            exit;
        } else if ($nowtime > $endtime) {
            $info = array(
                'error' => 4,
                'errStr' => '',
            );
            echo json_encode($info);
            exit;
        }
        if (!$fortunewheelLottery = ActivityModel::fortunewheelLottery($user['id'])) {
            $info = array(
                'error' => 2,
                'errStr' => '',
            );
            echo json_encode($info);
            exit;
        }
        $info = array(
            'error' => 0,
            'errStr' => '',
            'returnType' => $fortunewheelLottery['prize_type'],
            //'returnType' => 150,
            
        );
        echo json_encode($info);
        exit;
    }
    /*
     * 转轮分享激活处理
    */
    public function fortunewheelShare() {
        global $user, $language_id;
        if (!UserModel::logged()) {
            $info = array(
                'error' => 1,
                'errStr' => L('_USER_NO_LOGINED_') ,
            );
            echo json_encode($info);
            exit;
        }
        ActivityModel::fortunewheelAddShare($user['id']);
        $info = array(
            'error' => 0,
            'errStr' => '',
        );
        echo json_encode($info);
        exit;
    }
    /*
     * 转轮邮件分享处理
    */
    public function fortunewheelShareEmail() {
        global $user, $language_id;
        if (!UserModel::logged()) {
            echo 0;
            exit;
        }
        $fortunewheel_db = D('fortunewheel');
        $where = array(
            'user_id' => $user['id'],
        );
        $result = $fortunewheel_db->field('user_id,prize_type')->where($where)->find();
        if (!$result) {
            echo 0;
            exit;
        }
        $money = currency($result['prize_type']);
        $friendName = $_REQUEST['friendName'];
        $friendEmail = $_REQUEST['friendEmail'];
        $language = SiteModel::get_language_list();
        $lang = $language[$language_id];
        if ($lang['directory'] == 'en-us') {
            $url = 'http://www.' . APP_DOMAIN; //获得当前发送邮件中用户需要跳转域名地址
            
        } else {
            $url = 'http://' . $lang['directory'] . '.' . APP_DOMAIN;
        }
        $togoUrl = '<a href="' . $url . '/special/fortunewheel">' . $url . '/special/fortunewheel</a>';
        $titleOr = array(
            '{$user_name}'
        );
        $titleRe = array(
            $friendName
        );
        $contentOr = array(
            '{$user_name}',
            '{$money}',
            '{$url}',
            '{$date}'
        );
        $contentRe = array(
            $friendName,
            $money,
            $togoUrl,
            date('Y-m-d', time())
        );
        ActivityModel::sendXmasEmail($friendEmail, 'BlackFridayofInvi', $titleOr, $titleRe, $contentOr, $contentRe);
    }
    /*
     * 转轮得奖邮件处理
    */
    public function fortunewheelPrizeEmail() {
        global $user, $language_id;
        if (!UserModel::logged()) {
            exit;
        }
        $fortunewheel_db = D('fortunewheel');
        $where = array(
            'user_id' => $user['id'],
        );
        $result = $fortunewheel_db->field('user_id,prize_type')->where($where)->find();
        if ($result) {
            $language = SiteModel::get_language_list();
            $lang = $language[$language_id];
            if ($lang['directory'] == 'en-us') {
                $url = 'http://www.' . APP_DOMAIN; //获得当前发送邮件中用户需要跳转域名地址
                
            } else {
                $url = 'http://' . $lang['directory'] . '.' . APP_DOMAIN;
            }
            $togoUrl = '<a href="' . $url . '/special/fortunewheel">' . $url . '/special/fortunewheel</a>';
            $userInfo = UserModel::get_user_info($result['user_id']);
            $money = currency($result['prize_type']);
            $moneyDouble = currency($result['prize_type'] * 2);
            $contentOr = array(
                '{$money}',
                '{$moneyDouble}',
                '{$url}',
                '{$date}'
            );
            $contentRe = array(
                $money,
                $moneyDouble,
                $togoUrl,
                date('Y-m-d', time())
            );
            ActivityModel::sendXmasEmail($userInfo['email'], "BlackFridayofTips", false, false, $contentOr, $contentRe);
        }
    }
    /*
     * 转轮中奖后没有分享，超过一天
    */
    public function senda() {
        set_time_limit(0);
        ini_set('memory_limit', '512M');
        ActivityModel::sendEmailA();
    }
    /**
     * 转轮中奖后没有分享，超过一天
     */
    public function sendEmailA() {
        $fortunewheel_db = D('fortunewheel');
        $where = array(
            'id' => $_REQUEST['id'],
        );
        $val = $fortunewheel_db->where($where)->find();
        $userInfo = UserModel::get_user_info($val['user_id']);
        $language = SiteModel::get_language_list();
        if ($lang['directory'] == 'en-us') {
            $url = 'http://www.' . APP_DOMAIN; //获得当前发送邮件中用户需要跳转域名地址
            
        } else {
            $url = 'http://' . $lang['directory'] . '.' . APP_DOMAIN;
        }
        $togoUrl = '<a href="' . $url . '/special/fortunewheel">' . $url . '/special/fortunewheel</a>';
        $money = currency($val['prize_type']);
        $contentOr = array(
            '{$money}',
            '{$url}',
            '{$date}'
        );
        $contentRe = array(
            $money,
            $togoUrl,
            date('Y-m-d', time())
        );
        ActivityModel::sendXmasEmail($userInfo['email'], "BlackFridayofHintA", false, false, $contentOr, $contentRe, $userInfo['language_id']);
    }
    /*
     * 红包过期前3天（12月6日）
    */
    public function sendb() {
        set_time_limit(0);
        ini_set('memory_limit', '512M');
        ActivityModel::sendEmailB();
    }
    /**
     * 红包过期前3天（12月6日）
     */
    public function sendEmailB() {
        $fortunewheel_db = D('fortunewheel');
        $where = array(
            'id' => $_REQUEST['id'],
        );
        $val = $fortunewheel_db->where($where)->find();
        $userInfo = UserModel::get_user_info($val['user_id']);
        $language = SiteModel::get_language_list();
        $lang = $language[$userInfo['language_id']];
        if ($lang['directory'] == 'en-us') {
            $url = 'http://www.' . APP_DOMAIN; //获得当前发送邮件中用户需要跳转域名地址
            
        } else {
            $url = 'http://' . $lang['directory'] . '.' . APP_DOMAIN;
        }
        $togoUrl = '<a href="' . $url . '/category/2093-two-piece-suits">' . $url . '/category/2093-two-piece-suits</a>';
        $money = currency($val['prize_type']);
        $contentOr = array(
            '{$money}',
            '{$url}',
            '{$date}'
        );
        $contentRe = array(
            $money,
            $togoUrl,
            date('Y-m-d', time())
        );
        ActivityModel::sendXmasEmail($userInfo['email'], "BlackFridayofHintB", false, false, $contentOr, $contentRe, $userInfo['language_id']);
    }
    /*     public function graduationSeason()
    {
    global $user,$language_id;
    $data = array(
    		'docTitle' => 'Professional Suit for Interview | OWNONLY',
    		//'docKeywords' => L('meta_keywords'),
    		'docDescription' => 'High quality, reasonable price, exceptional customization, come and pick your first professional or casual suit in Uni.',
    	);
    	$this->assign($data);
    
    //西服
    $suitIdArr = '667,180,675,501';
    $suitIdArr = explode(',', $suitIdArr);
    //衬衫
    $shirtIdArr = '666,765,460,759';
    $shirtIdArr = explode(',', $shirtIdArr);
    
    
    $productList['suit'] = ProductModel::get_product_collection_list($suitIdArr,$language_id);
    $productList['shirt'] = ProductModel::get_product_collection_list($shirtIdArr,$language_id);
    
    $this->assign('productList',$productList);
    $this->display('special/graduation-season/index');
    } */
    public function clothingMatches() {
        $this->display('special/clothing-matches/index');
    }
    public function startBusiness() {
        $this->display('special/start-business/index');
    }
    public function mensNight() {
        $this->display('special/mens-night/index');
    }
    public function store() {
        $this->display('special/store/index');
    }
    public function wedding() {
        $this->display('special/wedding/index');
    }
	
	
    public function tenancy() {
       	
		$this->display('special/tenancy/index');
    }
	
	public function tenancy_do(){
		if ($this->isAjax ()){
			$data['name']		=	I("post.name",trim);
			$data['phone']		=	I("post.phone",trim);
			$data['sub_time']	=	strtotime(I("post.date",trim));
			$data['sex']		=	I("post.sex",trim);
			$data['createtime']	=	time();
			if(D('tenancy')->add($data)){
				$info=array("status"=>1,"msg"=>L('_succeed_'));
			}else{
				$info=array("status"=>0,"msg"=>L('_fail_'));
			}
		}else{
			$info=array("status"=>0,"msg"=>L('_fail_'));
		}
		 echo json_encode($info);exit;
	}
}

